# -*- coding: utf-8 -*-
"""
用户数据模型
定义用户相关的Pydantic模型
"""

from typing import Optional
from pydantic import BaseModel, EmailStr, Field, ConfigDict


class UserBase(BaseModel):
    """用户基础模型"""
    name: str = Field(..., min_length=1, max_length=50, description="用户姓名")
    email: EmailStr = Field(..., description="用户邮箱")
    age: int = Field(..., ge=1, le=150, description="用户年龄")


class UserCreate(UserBase):
    """创建用户模型"""
    pass


class UserUpdate(BaseModel):
    """更新用户模型"""
    name: Optional[str] = Field(None, min_length=1, max_length=50, description="用户姓名")
    email: Optional[EmailStr] = Field(None, description="用户邮箱")
    age: Optional[int] = Field(None, ge=1, le=150, description="用户年龄")


class User(UserBase):
    """用户完整模型"""
    id: int = Field(..., description="用户ID")
    
    model_config = ConfigDict(from_attributes=True)


class UserResponse(User):
    """用户响应模型"""
    pass


class UserListResponse(BaseModel):
    """用户列表响应模型"""
    users: list[UserResponse]
    total: int
    page: int = 1
    size: int = 10